//
//  Utils.m
//  小宝爱学
//
//  Created by imac on 15-8-13.
//  Copyright (c) 2015年 imac. All rights reserved.
//

#import "Utils.h"
#import "CustomDefine.h"

@implementation Utils
+(CGSize)getSizeByText:(NSString*)text andFontSize:(CGFloat)fontSize andMaxSize:(CGSize)maxSize{
    NSDictionary *dic=@{NSFontAttributeName:MFont(fontSize)};
    CGSize size=[text boundingRectWithSize:maxSize options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:dic context:nil].size;
    return size;
}

+(float)heightForString:(NSString *)value font:(UIFont*)font andWidth:(float)width
{
    
    CGSize s;
    if (IOS7) {
        s=[value boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil].size;
    }
    else
    {
        s=[value sizeWithFont:font constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
    }
    return s.height;
}

//+(CGFloat)getHeightByComment:(Comment*)comment{
//    CGFloat width=(__kWidth-30-20)/3;
//    
//    CGFloat textH;
//    if (IsNilString(comment.commentText)) {
//        textH=0;
//        
//    }else{
//        textH=[self heightForString:comment.commentText font:MFont(15) andWidth:__kWidth-30]+15;
//    }
//    CGFloat imagesH;
//    if (comment.images.count==0) {
//        imagesH=0;
//    }else if(comment.images.count<3){
//        imagesH=width+15;
//    }else{
//        imagesH=(width+15)*2;
//    }
//    return 15+15+textH+imagesH+15;
//    
//}

+(NSString*)getCurrentTime{
    NSDate *senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    dateformatter.dateFormat=@"YYYY-MM";
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    
    return locationString;
}
+(NSString*)getTextStrByText:(id)text{
    if (IsNull(text)) {
        return @"";
    }else if(IsNilString(text)){
        return @"";
    }else{
        return (NSString*)text;
    }
}
//+(UIImage*)getEvaluationImageByText:(NSString*)text{
//    UIImage *image;
//    if (IsEquallString(text, @"优秀")) {
//        image=MImage(@"Outstanding.png");
//    }else if(IsEquallString(text, @"良好")){
//        image=MImage(@"Good.png");
//    }else{
//        image=MImage(@"Moderate.png");
//    }
//    return image;
//}

+(BOOL)isYesByText:(NSString*)text{
    if (IsEquallString(text, @"是")) {
        return YES;
    }else{
        return NO;
    }
}
+(BOOL)isAuthenticationByText:(NSString*)text{
    if (IsEquallString(text, @"已验证")) {
        return YES;
    }else{
        return NO;
    }
}

@end
